package io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class BufferedInputFileMY {
	// Throw exceptions to console:
	public static String read(String filename) throws IOException {
		// Reading input by lines:
		BufferedReader in = new BufferedReader(new FileReader(filename));
		String s;
		StringBuilder sb = new StringBuilder();
		while ((s = in.readLine()) != null)
			sb.append(s + "\n");
		in.close();
		return sb.toString();
	}

	public static void main(String[] args) throws IOException {
		System.out.print(read( getJavaFilePath() + "BufferedInputFile.java"));
	}
	
	
	private static String getJavaFilePath() {
		StringBuilder sbb = new StringBuilder();
		String rootpath = BufferedInputFileMY.class.getClassLoader()
				.getResource("").getPath();
		String pkg = BufferedInputFileMY.class.getPackage().getName();
		// rootpath = rootpath.replaceAll("target[/\\\\]test-classes[/\\\\]",
		// "");
		rootpath = rootpath.replaceAll("\\\\", "/");
		rootpath = rootpath.replaceFirst("/", "");
		rootpath = rootpath.replaceAll("target/test-classes/", "");
		sbb.append(rootpath).append("src/main/java/")// .append("src/test/java/")
				.append(pkg).append("/");
		rootpath = sbb.toString();
		return rootpath;
	}
}
